import { FC, useState } from 'react'
import { usePage } from '@hs-admin/utils'
import { Button, Space } from 'antd'
import { HsAdminTablePage } from '@hs-admin/base-components'
import { getSettingAtlasList } from '@/api/setting/atlas'

const TablePage: FC = () => {
  const [data, setData] = useState([])
  const columns = [
    {
      title: '图谱名称',
      dataIndex: 'name',
      width: 200
    },
    {
      title: '图谱描述',
      dataIndex: 'description',
      width: 200,
      ellipsis: true
    },
    {
      title: '所属领域',
      dataIndex: 'domain.name',
      width: 200
    },
    {
      title: '最新维护时间',
      dataIndex: 'updated_at',
      type: 'datetime',
      width: 200
    },
    {
      title: '操作',
      key: 'action',
      render: () => (
        <Space>
          <Button type="link">编辑</Button>
          <Button type="link">删除</Button>
        </Space>
      )
    }
  ]

  const doRequest = () => {
    return getSettingAtlasList({
      page: pagination.current,
      page_size: pagination.pageSize
    }).then((res) => {
      setData(res.items)
      return res
    })
  }
  const { pagination } = usePage(doRequest)

  return (
    <>
      <HsAdminTablePage id="J-demo-resize-table" columns={columns} rowKey="id" dataSource={data} pagination={pagination}></HsAdminTablePage>
    </>
  )
}

export default TablePage
